﻿// <copyright file="ScriptArrayEnumerator.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2008-10-07</date>
// <summary>Script Array enumerator</summary>

namespace opensocial
{
    using System;
    using System.Collections.Generic;
    using System.Windows.Browser;

    /// <summary>
    /// Enumerator for ScriptArray
    /// </summary>
    public class ScriptArrayEnumerator : IEnumerator<ScriptObject>
    {
        /// <summary>
        /// script array to enumerate
        /// </summary>
        private ScriptArrayCollection scriptArray;

        /// <summary>
        /// current index for the script array
        /// </summary>
        private int index = -1;

        /// <summary>
        /// Initializes a new instance of the ScriptArrayEnumerator class.
        /// </summary>
        /// <param name="scriptArray">a script array</param>
        internal ScriptArrayEnumerator(ScriptArrayCollection scriptArray)
        {
            this.scriptArray = scriptArray;
        }

        #region IEnumerator<ScriptObject> Members

        /// <summary>
        /// Gets the current script object
        /// </summary>
        public ScriptObject Current
        {
            get 
            {
                return this.scriptArray[this.index];
            }
        }

        #endregion

        #region IEnumerator Members

        /// <summary>
        /// Gets the current item
        /// </summary>
        object System.Collections.IEnumerator.Current
        {
            get 
            {
                return this.scriptArray[this.index];     
            }
        }

        /// <summary>
        /// Dispose of the resources
        /// </summary>
        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// move to the next item in the collection
        /// </summary>
        /// <returns>true if there are more items in the collection</returns>
        public bool MoveNext()
        {
            this.index++;

            return this.index < this.scriptArray.length;
        }

        /// <summary>
        /// Reset the iterator
        /// </summary>
        public void Reset()
        {
            this.index = -1;
        }

        #endregion

        /// <summary>
        /// Dispose of the resources
        /// </summary>
        /// <param name="disposing">true if disposing</param>
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
            }

            this.index = 0;
            this.scriptArray = null;
        }
    }
}
